<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core\lang;
use classlib\core as C;
use classlib\core\controller;
class Cpayrecord extends controller {
	public function main() {
		$view  = C\view::inst('extjs');
		Cadmin::chkaccess($view);
		$dlang = C\lang::inst('dd');
		$view->assign('status', $dlang->get('pay_status'));
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('live/payrecord.ext.js');
	}
	
	/**
	 * 获取充值信息资料列表
	 */
	public function dolist() {
		$view   = C\view::inst('json');
		Cadmin::chkaccess($view);
		list($start, $limit, $sort) = Cadmin::offset();
		$where  = array();
		$bzsn   = input::post('bzsn');
		if ($bzsn && !empty($bzsn)) {
			$where[] = array('bzsn', $bzsn, \classlib\orm::OP_EQ);
		}
		$paysn  = input::post('paysn');
		if ($paysn && !empty($paysn)) {
			$where[] = array('paysn', '%'.$paysn.'%', \classlib\orm::OP_LIKE);
		}
		$status = input::post('status');
		is_numeric($status) && $where['status'] = $status;
		$userid = input::post('userid');
		is_numeric($userid) && $where['userid'] = $userid;
		$sdate  = input::post('sdate');
		if ($sdate) {
			$where[] = array('paytime', strtotime($sdate), \classlib\orm::OP_GT);
		}
		$edate  = input::post('edate');
		if ($edate) {
			$where[] = array('paytime', strtotime($edate), \classlib\orm::OP_LT);
		}
		$orm    = C\model::load('pro.pl.payrecords');
		$total  = $orm->get_total($where);
		$list   = array();
		if ($total > 0) {
			$state= $orm->get_item($where, 'sum(money) as money, sum(coin) as coin');
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			$uorm = C\model::load('pro.pl.userinfo');
			foreach ($list as &$item) {
				$user = $uorm->get_one($item['userid']);
				$item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
				$item['paytime'] = date('Y-m-d H:i:s', $item['paytime']);
				$item['stime']   = date('Y-m-d H:i:s', $item['stime']);
				$item['nickname']= $user['nickname'];
			}
			$list[] = array('userid'=>'statistics', 'money'=>$state['money'], 'coin'=>$state['coin']);
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}